import 'package:flutter/material.dart';
import 'package:wis_flutter/index.dart';        // wis flutter 组件 

import 'package:wis_flutter/bottomBar.dart';     // 底部导航条




// 组织树  页面
class TreeviewPage extends StatefulWidget {
  TreeviewPage({Key key}) : super(key: key);
  @override
  _TreeviewPageState createState() => _TreeviewPageState();
}

class _TreeviewPageState extends State<TreeviewPage> {

     List _list = [];   // 组织树 数据


    @override
    void initState() {
      super.initState();

      this.initPage();   // 初始化
    }


    void initPage() async{

      await new Future.delayed(new Duration(seconds: 3));
      List _newList=[
          {
            "label": "一级标题",
            "children": [
              {"label": "Alabama", "key": "AL"},
              {"label": "Alaska", "key": "AK"},
            ]
          },
          {
            "label": "第一级-多层的",
            "children": [
              {
                "label": "第二级", 
                "key": "B1",
                "children": [
                  {"label": "第三级111", "key": "B21"},
                  {"label": "第三级222", "key": "B22"},
                ]
              },
              {"label": "Alaska", "key": "B2"},
            ]
          },  
        ];
    
      // 模拟数据
      setState(() {
        _list = _newList;         
      });

    }

    @override
    Widget build(BuildContext context) {

      return Scaffold(
        appBar: AppBar( title: const Text('组织树') ),  // 头部导航条
        bottomNavigationBar: BottomBarWidget(),       // 底部导航条
        backgroundColor: Colors.blue[10],
        body: GestureDetector(
          onTap: () {
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: Container(
            padding: EdgeInsets.all(8),
            child: WisTreePage(
              height: 200,   // 高度  默认 300
              children: _list,
              // 展开事件
              onExpansionChanged: (key, expanded){
                // print(key);
                // print(expanded);   //是否展开
              },              
              // 点击 最后一层
              onClick:(key){
                print(key);
              }
            ),
          )
        
        )
      ); 
    }
}